package service;

import java.io.BufferedInputStream;
import java.io.ByteArrayOutputStream;
import java.io.DataInputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileWriter;
import java.io.IOException;
import java.io.InputStream;
import java.net.MalformedURLException;
import java.net.URL;
import java.sql.Connection;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.sound.sampled.AudioFormat;
import javax.sound.sampled.AudioInputStream;
import javax.sound.sampled.AudioSystem;
import javax.sound.sampled.DataLine;
import javax.sound.sampled.LineUnavailableException;
import javax.sound.sampled.SourceDataLine;
import javax.sound.sampled.TargetDataLine;
import javax.sound.sampled.UnsupportedAudioFileException;
import javax.swing.JFrame;

import org.json.JSONObject;
import org.tritonus.sampled.convert.PCM2PCMConversionProvider;
import org.tritonus.share.sampled.convert.*;

import dao.ConnectDB;
import dao.OperateDB;
import service.Complex;
import service.FFT;
import service.DataPoint;
import pojo.Comment;
import pojo.Reco;
import pojo.Song;
import pojo.SongList;
import pojo.User;
import util.GetPath;
import util.JsonBuilder;
import util.JsonParser;
import util.SerializeObject;

public class PBManager implements PlayerBusiness {

	private OperateDB operateDB = new OperateDB();
	private JsonBuilder jsonBuilder = new JsonBuilder();
	private JsonParser jsonParser = new JsonParser();
	private GetPath getPath = new GetPath();
//	Song song1=new Song();
//	Song song2=new Song();
//	Song song3=new Song();
//	Song song4=new Song();
	

	boolean running = false;
	double highscores[][]; // ��Ӧÿ��range��Χ����ߵ�
	double recordPoints[][]; // ��ߵ��������е�ԭʼλ��
	long points[][]; // ��ߵ��ʱ��λ��
	Map<Long, List<DataPoint>> hashMap = new HashMap<Long, List<DataPoint>>();
	Map<Integer, Map<Integer, Integer>> matchMap; // Map<SongId,Map<Offset,count>>

	//List<Song> list = new ArrayList<Song>();

	int[] idArray = new int[] { 28892408, 22832010, 26145724, 22762624 };
	public final int UPPER_LIMIT = 300;
	public final int LOWER_LIMIT = 40;
	public final int[] RANGE = new int[] { 40, 80, 120, 180, UPPER_LIMIT + 1 };

	private static final int FACTOR = 2;

	private long hash(long p1, long p2, long p3, long p4) { // �Զ����ϣɢ���㷨
		return (p4 - (p4 % FACTOR)) * 100000000 + (p3 - (p3 % FACTOR)) * 100000 + (p2 - (p2 % FACTOR)) * 100
				+ (p1 - (p1 % FACTOR));
	}

	private AudioFormat getFormat() { // ¼����������
		float sampleRate = 44100;
		int sampleSizeInBits = 8;
		int channels = 1; // mono
		boolean signed = true;
		boolean bigEndian = false;// ��С��Ӱ�첻��
		return new AudioFormat(sampleRate, sampleSizeInBits, channels, signed, bigEndian);
	}

	private synchronized SourceDataLine getLine(AudioFormat audioFormat) // �������������ݵ�TargetDataLine�����Դ�TargetDataLine��ȡ���ݣ�������ͨ��InputStreamһ��
			throws LineUnavailableException {
		SourceDataLine res = null;
		DataLine.Info info = new DataLine.Info(SourceDataLine.class, audioFormat);
		res = (SourceDataLine) AudioSystem.getLine(info);
		res.open(audioFormat);
		return res;
	}

	// �ҵ����ĸ���Χ
	public int getIndex(int freq) {
		int i = 0;
		while (RANGE[i] < freq)
			i++;
		return i;
	}

	public void readMp3(Reco reco) {
		// idArray=new int[]{1,2,3,4,5,6,7,8,9};
		// recognizeSong(null, idArray[0], false,
		// "C:/Users/robin/Music/m1.mp3");
		// recognizeSong(null, idArray[1], false,
		// "C:/Users/robin/Music/m2.mp3");
		// recognizeSong(null, idArray[2], false,
		// "C:/Users/robin/Music/m3.mp3");
		// recognizeSong(null, idArray[3], false,
		// "C:/Users/robin/Music/m4.mp3");
		// recognizeSong(null, idArray[4], false,
		// "C:/Users/robin/Music/m5.mp3");
		// recognizeSong(null, idArray[5], false,
		// "C:/Users/robin/Music/m6.mp3");
		// recognizeSong(null, idArray[6], false,
		// "C:/Users/robin/Music/m7.mp3");
		// recognizeSong(null, idArray[7], false,
		// "C:/Users/robin/Music/m8.mp3");
		// recognizeSong(null, idArray[8], false,
		// "C:/Users/robin/Music/m9.mp3");

		
		recognizeSong(null, idArray[0], false, getPath.getExamplePath() + "m8.mp3");
		recognizeSong(null, idArray[1], false, getPath.getExamplePath() + "m4.mp3");
		recognizeSong(null, idArray[2], false, getPath.getExamplePath() + "m7.mp3");
		recognizeSong(null, idArray[3], false, getPath.getExamplePath() + "m6.mp3");

		reco.setMap(hashMap);
		
		List<Song> songs = new ArrayList<Song>();

		Song song1 = new Song();
		song1.setSongId(idArray[0]);
		String string=song1.getSongId()+"";
		System.out.println(string);
		
		
		song1.setTitle("我的天空 by 南征北战");
		song1.setAlbumId(1);
		song1.setSongUrl("http://m2.music.126.net/Noz6iMtUdhPDtW5v8CpEHA==/8922536859432785.mp3");
		// list.add(song1);
		songs.add(song1);

		Song song2 = new Song();
		song2.setSongId(idArray[1]);
		song2.setTitle("光辉岁月 by beyonds");
		song2.setAlbumId(2);
		song2.setSongUrl("http://m2.music.126.net/iwy74WUuQBe_jsnWRCuB1w==/1013749720819585.mp3");
		// list.add(song2);
		songs.add(song2);

		Song song3 = new Song();
		song3.setSongId(idArray[2]);
		song3.setTitle("青城山下白素贞 by 好妹妹乐队");
		song3.setAlbumId(3);
		song3.setSongUrl("http://m2.music.126.net/QfYdNvAuP8GAeyk3cW5emg==/7989051489062317.mp3");
		// list.add(song3);
		songs.add(song3);

		Song song4 = new Song();
		song4.setSongId(idArray[3]);
		song4.setTitle("月亮代表我的心 by 邓丽君");
		song4.setAlbumId(4);
		song4.setSongUrl("http://m2.music.126.net/iI7HYft4q9kkBUlDd8gTQA==/2769669790377513.mp3");
		// list.add(song4);
		songs.add(song4);
		reco.setSongs(songs);
	}

	public String readSource() {
		
		ByteArrayOutputStream out = new ByteArrayOutputStream();
		File file = new File(getPath.getRawPath() + "second.raw");
		byte data;
		InputStream is = null;
		try {
			is = new FileInputStream(file);
		} catch (FileNotFoundException e) {
			e.printStackTrace();
		}
		BufferedInputStream bis = new BufferedInputStream(is);
		DataInputStream dis = new DataInputStream(bis);
		int size = 0;
		int i = 0;
		try {
			while (dis.available() > 0) {
				data = dis.readByte();
				out.write(data);
				i++;

			}
		} catch (IOException e) {

			e.printStackTrace();
		}finally{
			try {
				is.close();
				out.close();
				bis.close();
				dis.close();
			} catch (IOException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
			
		}
		return recognizeSong(out, 0, true, null);
	}

	@Override // ¼���ƥ���и���Ҷ�任���趼Ҫ��������������ת�����������ȷ���ؼ��㲽��ͨ�������isMatching�ؼ������жϷֿ�����
	public String recognizeSong(ByteArrayOutputStream out, long songId, boolean isMatching, String filePath) {
		AudioFormat formatTmp = null;
		TargetDataLine lineTmp = null;

		AudioInputStream din = null;
		AudioInputStream outDin = null;
		PCM2PCMConversionProvider conversionProvider = new PCM2PCMConversionProvider(); // ����ת��
		boolean isMicrophone = false;

		if (isMatching != true) {

			AudioInputStream in = null;

			// **����Ļ�ȡin����Ĵ������������룬������Ҫ�Ķ���ͨ��url�����ϻ�ȡ�����������䴦������hashmap�����ݿ��

			// URL url = new URL("http://www.baidu.com");
			// in = AudioSystem.getAudioInputStream(url);

			File file = new File(filePath); // �ӱ���·���л�ȡ����
			System.out.println(filePath);
			try {
				in = AudioSystem.getAudioInputStream(file);
			} catch (UnsupportedAudioFileException e1) {
				e1.printStackTrace();
			} catch (IOException e1) {
				e1.printStackTrace();
			}

			// if (filePath.contains("http")) { // �������ϻ������
			// URL url = new URL(filePath);
			// in = AudioSystem.getAudioInputStream(url);
			// }
			// else { //�������ñ��ش���������ļ����ԣ����ڿ϶�Ҫ�������е������ļ�
			// File file = new File(filePath); // �ӱ���·���л�ȡ����
			// in = AudioSystem.getAudioInputStream(file);
			// }

			AudioFormat baseFormat = in.getFormat();

			AudioFormat decodedFormat = new AudioFormat( // ����������ʽ
					AudioFormat.Encoding.PCM_SIGNED, baseFormat.getSampleRate(), 16, baseFormat.getChannels(),
					baseFormat.getChannels() * 2, baseFormat.getSampleRate(), false);

			din = AudioSystem.getAudioInputStream(decodedFormat, in);

			if (!conversionProvider.isConversionSupported(getFormat(), // ��������ת��Ϊ��������getFormat()
					decodedFormat)) {
				System.out.println("Conversion is not supported");
			}

			outDin = conversionProvider.getAudioInputStream(getFormat(), din);
			formatTmp = decodedFormat;

			DataLine.Info info = new DataLine.Info(TargetDataLine.class, formatTmp);
			try {
				lineTmp = (TargetDataLine) AudioSystem.getLine(info);
			} catch (LineUnavailableException e) {

				e.printStackTrace();
			}

			final AudioFormat format = formatTmp; // ����ת����ĸ�ʽ
			final TargetDataLine line = lineTmp;
			final boolean isMicro = isMicrophone;
			final AudioInputStream outDinSound = outDin;

			final long sId = songId;
			final boolean isMatch = isMatching;

			// ����Ĳ����Ͳ����߳��ˣ������ϸ����ܶ�ʱ�򣬲����߳�̫�࣬�ᳬ������������
			ByteArrayOutputStream out1 = new ByteArrayOutputStream();
			running = true;
			int n = 0;
			byte[] buffer = new byte[(int) 1024];

			while (true) {
				n++;
				if (n > 1000) // ������1024*1000���ֽڣ����ӽ�1M��ֹͣ����
					break;
				int count = 0;
				try {
					count = outDinSound.read(buffer, 0, 1024);
				} catch (IOException e) {

					e.printStackTrace();
				}
				if (count > 0) {
					out1.write(buffer, 0, count);
				}
			}

			out = out1;

			// byte b[] = out.toByteArray(); // ��ӡ����ֽ����ķ���
			// for (int i = 0; i < b.length; i++) { //������ʱ�򣬰�����ص���Ӱ��Ч��
			// System.out.print(b[i]+" ");
			// }
			// System.out.println();
			// System.out.println("��ӡ����");
			line.close();
		}

		String msg = makeSpectrum(out, songId, isMatching);
		try {
			out.close();
		} catch (IOException e) {
			e.printStackTrace();
		}

		return msg;
	}

	public String makeSpectrum(ByteArrayOutputStream out, long songId, boolean isMatching) { // 2.ʵ�ָ���Ҷ�任
		byte audio[] = out.toByteArray();
		final int totalSize = audio.length;
		int amountPossible = totalSize / 4096; // һ����chunk��С4096�ֽ�
		Complex[][] results = new Complex[amountPossible][];
		for (int times = 0; times < amountPossible; times++) {
			Complex[] complex = new Complex[4096];
			for (int i = 0; i < 4096; i++) {
				complex[i] = new Complex(audio[(times * 4096) + i], 0); // �鲿Ϊ0
			}
			results[times] = FFT.fft(complex); // ��ÿһ������и���Ҷ�任
		}
		String msg = determineKeyPoints(results, songId, isMatching);
		return msg;

	}

	public String determineKeyPoints(Complex[][] results, long songId, boolean isMatching) {
		
		this.matchMap = new HashMap<Integer, Map<Integer, Integer>>(); // Map<SongId,
																		// Map<Offset,
																		// Count>>

		highscores = new double[results.length][5];
		for (int i = 0; i < results.length; i++) {
			for (int j = 0; j < 5; j++) {
				highscores[i][j] = 0;
			}
		}

		recordPoints = new double[results.length][UPPER_LIMIT]; // һ���൱��һ��chunk
		for (int i = 0; i < results.length; i++) {
			for (int j = 0; j < UPPER_LIMIT; j++) {
				recordPoints[i][j] = 0;
			}
		}

		points = new long[results.length][5];
		for (int i = 0; i < results.length; i++) {
			for (int j = 0; j < 5; j++) {
				points[i][j] = 0;
			}
		}

		for (int t = 0; t < results.length; t++) {
			for (int freq = LOWER_LIMIT; freq < UPPER_LIMIT - 1; freq++) {
				double mag = Math.log(results[t][freq].abs() + 1); // ��1��֤magΪ����
				int index = getIndex(freq);
				if (mag > highscores[t][index]) {
					highscores[t][index] = mag; // ��¼��ߵ�����
					recordPoints[t][freq] = 1;
					points[t][index] = freq; // ��¼��ߵ�ʱ��
				}
			}

			// try {
			// for (int k = 0; k < 5; k++) {
			// // outFile.write("" + highscores[t][k] + ";" +
			// // recordPoints[t][k] + "\t"); // �ؼ������ݴ浽result�ļ���
			// // // ÿһ�飨Ҳ���ļ����ÿһ�У�5���ؼ�������
			// outFile.write("" + points[t][k] + "\t");
			// }
			// outFile.write("\n");
			//
			// } catch (IOException e) {
			// e.printStackTrace();
			// }

			long h = hash(points[t][0], points[t][1], points[t][2], // ȡǰ�ĸ���Χ�ڵ���ߵ�ʱ����Ϊ��ϣɢ��
					points[t][3]);

			if (isMatching) { // �����ƥ������Ļ���Ҫ���еĲ���
				GetPath getPath = new GetPath();
				String objectPath = getPath.getObjectPath();
				SerializeObject serializeObject = new SerializeObject();
				Reco reco = serializeObject.getObject(objectPath);
				Map<Long, List<DataPoint>> hashMap = reco.getMap();
				
				List<DataPoint> listPoints;

				// **���ʱ��Ҫ�����ݿ���hashmap���ݶ������ŵ�hashMap��
				if ((listPoints = hashMap.get(h)) != null) { // Map<Long,List<DataPoint>>
																// hashMap;
																// list���ŵ��ǲ�ͬ�ĸ������Լ�ÿ�������������long����ʱ��ʱ��λ��
					for (DataPoint dP : listPoints) {
						int offset = Math.abs(dP.getTime() - t); // ʱ���
						Map<Integer, Integer> tmpMap = null;
						if ((tmpMap = this.matchMap.get(dP.getSongId())) == null) { // Map<SongId,Map<Offset,Count>>
							tmpMap = new HashMap<Integer, Integer>();
							tmpMap.put(offset, 1);
							matchMap.put(dP.getSongId(), tmpMap);
						} else {
							Integer count = tmpMap.get(offset); // ֻҪ����һ��offset���ʹ�����ĳ������ĳ��ϣɢ�к��䣨�����ϣɢ�м�h��ƥ�����ˣ�
							if (count == null) { // ��ôoffsetֵԽС����countֵԽ��ĸ����ʹ���Խƥ�䣨�������ƥ�䣺ʱ���ϵ�ƥ��offset,�����ϵ�ƥ��count��
								tmpMap.put(offset, new Integer(1));
							} else {
								tmpMap.put(offset, new Integer(count + 1));
							}
						}
					}
				}

			} else { // **�Ժ�Ҫ�����hashmap�����ݴ浽���ݿ���
				// �������ƥ������Ļ����ͰѸ�������Ϣ�浽hashMap��
				List<DataPoint> listPoints = null;
				if (hashMap == null) {
					System.out.println("hashMapΪ��");
				}
				if ((listPoints = hashMap.get(h)) == null) {
					listPoints = new ArrayList<DataPoint>();
					DataPoint point = new DataPoint((int) songId, t);
					listPoints.add(point);
					hashMap.put(h, listPoints);
				} else {
					DataPoint point = new DataPoint((int) songId, t);
					listPoints.add(point);
				}
			}
		}

		// **������� �ҵ�����������ƥ����� ����
		if (isMatching) {
			List<DataPoint> listPoints1;
			int bestCount = 0;
			int bestSong = -1;
			// **�����ѭ������������������ʹ�����ݿ����Ҫ�Ķ������õ�songId����Ϊ0��matchMapû��ֵ������£�songIdҲ����Ϊ0
			for (int id = 0; id < 4; id++) {
				//System.out.println("For song id: " + idArray[id]);
				Map<Integer, Integer> tmpMap = matchMap.get(idArray[id]);
				int bestCountForSong = 0;
				if (tmpMap == null) { // ����ò��ո���û���κ�һ���Ĺ�ϣɢ�У�ֱ������
					System.out.println("���� " + idArray[id] + " ����");
					continue;
				}
				for (Map.Entry<Integer, Integer> entry : tmpMap.entrySet()) {
					if (entry.getValue() > bestCountForSong) { // ����¼���ƥ������겻������ֻҪ����ԭ���е�ĳһС�Σ���ƥ�����ˣ�������ͬ�����ƣ���ԭ���¼��ĸ趼�����С���ƣ���
						bestCountForSong = entry.getValue(); // Ҳ�ᱣ֤��ͬһ��offset��
																// count�ͻ������offset���ۼ�
																// ��ֻ��Ѱ�ҵ�����count�Ϳ���
					}
					// System.out.println("Time offset = " + entry.getKey() + ",
					// Count = " + entry.getValue());
				}

				if (bestCountForSong > bestCount) {
					bestCount = bestCountForSong;
					bestSong = idArray[id];
				}
			}

			System.out.println("Best song id: " + bestSong);
 			List<Song> list = new ArrayList<Song>();
			GetPath getPath = new GetPath();
			String objectPath = getPath.getObjectPath();
			SerializeObject serializeObject = new SerializeObject();
			Reco reco = serializeObject.getObject(objectPath);
			List<Song> songList = reco.getSongs();

			switch (bestSong) {
			case 28892408:
				list.add(songList.get(0));
				System.out.println(songList.get(0).getSongId());
				return jsonBuilder.buildSongs(list);
			case 22832010:
				list.add(songList.get(1));
				return jsonBuilder.buildSongs(list);
			case 26145724:
				list.add(songList.get(2));
				return jsonBuilder.buildSongs(list);
			case 22762624:
				list.add(songList.get(3));
				return jsonBuilder.buildSongs(list);
			default:
				return jsonBuilder.buildInvalidInfo("sorry,no match song!");

			}

			// **���ڷ��ذ����������ַ����ڿͻ�����ʾ������û�������ŵĻ���������������󲥷ţ�������ѡ�貥��һ����
			// return bestSong+"";
			// **bestSong=-1����ƥ��û��ƥ��ĸ��������ʺ�С����ҲҪ����һ���������

		} else {
			return null;
		}
	}

	@Override
	public String regUser(String uname, String passw, String email) { // ע�����
		// TODO Auto-generated method stub
		User user = new User();
		user.setUserName(uname);
		user.setPassword(passw);
		user.setEmail(email);

		Date now = new Date();
		SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss");// ���Է�����޸����ڸ�ʽ
		String createdTime = dateFormat.format(now);
		user.setCreatedTime(createdTime);

		boolean mark = operateDB.addUser(user);
		if (mark == true) {
			return jsonBuilder.buildValidInfo("regist success");
		} else {
			return jsonBuilder.buildInvalidInfo("regist failed");
		}

	}

	@Override
	public String findUser(String uname, String passw) { // ��¼�ж�
		// TODO Auto-generated method stub
		User user = operateDB.findUser(uname, passw);
		if (user == null) {
			return jsonBuilder.buildInvalidInfo("login failed");
		} else {
			return jsonBuilder.buildUpdatedData(operateDB.findAllSongs(uname, passw));
		}

	}

	public String getUser(int uid) { // �鿴�û���Ϣ
		User user = operateDB.findUser(uid);
		if (user == null) {
			return jsonBuilder.buildInvalidInfo("user not exist");
		} else {
			return jsonBuilder.buildUser(user);
		}
	};

	@Override
	public String createSlist(int uid, String slistName) { // �½��赥
		// TODO Auto-generated method stub
		Date now = new Date();
		SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss");// ���Է�����޸����ڸ�ʽ
		String createdTime = dateFormat.format(now);

		boolean mark = operateDB.addSongList(uid, slistName, createdTime);
		if (mark == true) {
			return jsonBuilder.buildValidInfo("create songlist success");

		} else {
			return jsonBuilder.buildInvalidInfo("create songlist failed");
		}

	}

	@Override
	public String deleteSlist(int slistId) { // ɾ���赥
		// TODO Auto-generated method stub
		boolean mark = operateDB.deleteSongList(slistId);
		if (mark == true) {

			return jsonBuilder.buildValidInfo("delete songlist success");
		} else {
			return jsonBuilder.buildInvalidInfo("delete songlist failed");
		}

	}

	@Override
	public String modifySlist(int songListId, String songListName, String description) { // �޸ĸ赥
		// TODO Auto-generated method stub
		Date now = new Date();
		SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss");// ���Է�����޸����ڸ�ʽ
		String modifiedTime = dateFormat.format(now);
		boolean mark = operateDB.updateSongList(songListId, songListName, description, modifiedTime);
		if (mark == true) {
			return jsonBuilder.buildValidInfo("update songlist success");
		} else {
			return jsonBuilder.buildInvalidInfo("update songlist failed");

		}

	}

	@Override
	public String findAllSlist(int uid) { // ��ѯ�赥(����赥)
		// TODO Auto-generated method stub
		return jsonBuilder.buildUpdatedData(operateDB.findAllSongs(uid));

	}

	@Override
	public String getComment(int songId) { // �鿴����
		// TODO Auto-generated method stub
		List<Comment> list;
		list = operateDB.findComment(songId);
		return jsonBuilder.buildComments(list);
	}

	@Override
	public String addComment(Comment comment) { // �������
		// TODO Auto-generated method stub
		// List<Comment> list = jsonParser.parseComments(commmentJson);
		// for (Comment clist : list) {
		boolean mark = operateDB.addCommnet(comment);
		if (mark == false) {
			return jsonBuilder.buildInvalidInfo("add comment failed");
		}
		// }

		return jsonBuilder.buildValidInfo("add comment success");
	}

	@Override
	public String deleteComment(int commentId) { // ɾ������
		// TODO Auto-generated method stub
		boolean mark = operateDB.deleteComment(commentId);
		if (mark == true) {
			return jsonBuilder.buildValidInfo("delete comment success");
		} else {
			return jsonBuilder.buildInvalidInfo("delete comment failed");
		}

	}

	@Override
	public String getSong(String songName) { // ����������
		// TODO Auto-generated method stub
		return jsonBuilder.buildSongs(operateDB.findSongs(songName));

	}

	@Override
	public String addSongInList(int songid, int slistId) { // �赥��Ӹ���
		// TODO Auto-generated method stub
		boolean mark = operateDB.addSong_SongList(songid, slistId);
		if (mark == true) {
			return jsonBuilder.buildValidInfo("add songinlist success");
		} else {
			return jsonBuilder.buildInvalidInfo("add songinlist failed");
		}
	}

	@Override
	public String deleteSongInList(int songId, int slistId) { // �赥ɾ������
		// TODO Auto-generated method stub
		boolean mark = operateDB.deleteSong_SongList(songId, slistId);
		if (mark == true) {
			return jsonBuilder.buildValidInfo("delete songinlist success");

		} else {
			return jsonBuilder.buildInvalidInfo("delete songinlist failed");
		}

	}

	@Override
	public String modifyDescription(int songListId, String songListName, String description) { // �赥�޸�������Ϣ
		// TODO Auto-generated method stub
		Date now = new Date();
		SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss");// ���Է�����޸����ڸ�ʽ
		String modifiedTime = dateFormat.format(now);
		boolean mark = operateDB.updateSongList(songListId, songListName, description, modifiedTime);
		if (mark == true) {
			return jsonBuilder.buildValidInfo("update songlist success");
		} else {
			return jsonBuilder.buildInvalidInfo("update songlist failed");
		}

	}

	// public static void main(String[] args) {
	// PBManager pbManager=new PBManager();
	// pbManager.readMp3();
	// pbManager.readSource();
	// }

}
